<?php
namespace app\admin\controller;

use app\BaseController;
use app\admin\model\{SystemMenus as SystemMenusModel};
use app\admin\validate\PositiveIntegerValidate;
use app\Request;

class SystemMenus extends BaseController
{
    public function getMenusTrees(Request $request)
    {
        $this->success('success', SystemMenusModel::menusTrees(), 200);
    }

    public function createOrUpdateMenu(Request $request)
    {
        $data = $request->post();
        $this->success('success', SystemMenusModel::menuCreateOrUpdate($data), 201);
    }

    public function getMenuList(Request $request)
    {
        $param = $request->get();
        $this->success('success', SystemMenusModel::menuList($param), 200);
    }

    public function delMenu(Request $request)
    {
        (new PositiveIntegerValidate)->checkParams();

        $id = $request->param('id');
        $this->success('success', SystemMenusModel::delMenu($id), 204);
    }

    public function updateMenu(Request $request)
    {
        (new PositiveIntegerValidate)->checkParams();

        $id = $request->param('id');
        $this->success('success', SystemMenusModel::updateMenu($id), 201);
    }

    public function getAllMenus() 
    {
        $this->success('success', SystemMenusModel::getAllMenusList(), 200);
    }
}